﻿using AutoMapper;

namespace WPF.Core
{
    public interface IAppMapper
    {
        IMapper Current { get; }

        IDestination  Map<IDestination>(Object source);
    }

    /// <summary>
    /// 实体模型映射服务
    /// </summary>
    public class AppMapper : IAppMapper
    {
        public AppMapper()
        {
            var config = new MapperConfiguration(config =>
            {
                var assemblys = AppDomain.CurrentDomain.GetAssemblies();
                config.AddMaps(assemblys);
            });
            Current = config.CreateMapper();
        }

        /// <summary>
        /// AutoMapper 内部转换接口
        /// </summary>
        public IMapper Current { get; set; } 

        public IDestination Map<IDestination>(object source)
        {
           return Current.Map<IDestination>(source);
        }
    }
}
